from Autotests.BaseTest import AirManagerTestCase
from Autotests.LocalMachine.Pages.AirManager.UserSettingsPage.UserTab import UserTab, Role
from Autotests.LocalMachine.Pages.AirManager.MainPage import WebMainPage
import time

class Users(AirManagerTestCase):
    def test_AddEditDeleteUser(self):
        email = "address+%s@example.com" % str(int(time.time()))
        name = "UserName"
        password = "q1w2e3r4"
        role = Role.user
        userTab = UserTab()

        userList = userTab.getUserList()
        userTab.addUser(email, name, password, role)
        userListAfterAdd = userTab.getUserList()
        self.assertEqual(len(userList)+1, len(userListAfterAdd), "User count hasn't been incremented after adding  user")
        self.assertTrue(email in userListAfterAdd, "User hasn't been added in UserTable")

        userTab.editUserRole(email, Role.superUser)
        userListAfterEdit = userTab.getUserList()
        self.assertEqual(len(userList)+1, len(userListAfterEdit), "User count has been changed after modifying user")
        self.assertEqual(Role.superUser, userTab.getUserRole(email), "User role hasn't been modified")

        userTab.deleteUser(email)
        userListAfterDelete = userTab.getUserList()
        self.assertEqual(len(userList), len(userListAfterDelete), "User count hasn't been decremented after adding  user")
        self.assertTrue(email not in userListAfterDelete, "User hasn't been removed from UserTable")


import unittest
if __name__ == "__main__":
    unittest.main()
